package com.itheima.d3_voteMapDemo;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * 某个班级80个学生，班长提供了 A B C D四个景点， 每个学生只能选择一个景点；统计出最终哪个景点
 * <Student,景点名>; 这样是比较好的数据结构
 */
public class voteMap {
    public static void main(String[] args) {
        String[] spots = {"A","B","C","D"};
        Map<Student,String> maps = new HashMap<>();
        Random random = new Random();
        for (int i = 0; i < 80; i++) {
            int index = random.nextInt(4);
            Student student = new Student();
            student.setName("student"+i);
            maps.put(student,spots[index]);
        }
        System.out.println(maps);
        int spotA=0;
        int spotB=0;
        int spotC=0;
        int spotD=0;
        Set<Student> studentSet = maps.keySet();
        for (Student s : studentSet){
            String value = maps.get(s);
            if("A".equals(value)){
                spotA++;
            }else if("B".equals(value)){
                spotB++;
            }else if("C".equals(value)){
                spotC++;
            }else{
                spotD++;
            }
        }
        System.out.println("A景点人数："+spotA);
        System.out.println("B景点人数："+spotB);
        System.out.println("C景点人数："+spotC);
        System.out.println("D景点人数："+spotD);
    }
}

class Student{
    private String name;


    public Student() {
    }

    public Student(String name) {
        this.name = name;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}